home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * FindFamilies
- *
- * (C) Copyright Apple Computer, Inc. 1992
- * All rights reserved.
- *
- * by Matt Deatherage
- * Friday, October 2, 1992
- *
- * FindFamilies is an MPW tool that looks through 'FOND' resources. You feed it
- * the name of a font family (like "Courier") and it examines the 'FOND' resource
- * for that family, printing the size and IDs of all resources that the 'FOND'
- * references. It then walks through all your installed fonts and finds where
- * those are referenced.
- *
- * This is primarily useful for finding where style-linked fonts reside. For
- * example, most fonts that ship with multiple styles include 'FOND' resources
- * describing the font and the main family. MyFont Bold might have a 'FOND'
- * for a family named 'MyFont Bold' as well as a 'FOND' indicating it's the
- * "bold" entry for 'MyFont'.
- *
- * Weird, huh? As an example, I have the Monotype family Gill Sans installed
- * on my system. The suitcase for "GillSans Bold" contains two entries -- one
- * indicating that the main font is the "plain" variety of "GillSans Bold" and
- * one indicating that Gill Sans Bold Italic is the "italic" variety of "GillSans
- * Bold". GillSans Bold itself, though is the "bold" variety of "GillSans", so
- * there are multiple 'FOND's referencing the same fonts. This reveals that
- * relationship. Here's the sample output:
- *
- * findfamilies "GillSans Bold"
- * Source FOND GillSans Bold contains 1 entries:
- *
- * Entry 0: Size 12, ID 30684
- * Entry 1: Size 12, ID 30671
- *
- * Now checking family: GillSans
- * GillSans includes size 12 and ID 30684.
- * GillSans includes size 12 and ID 30671.
- * Now checking family: GillSans Bold
- * GillSans Bold includes size 12 and ID 30684.
- * GillSans Bold includes size 12 and ID 30671.
- * Now checking family: GillSans Condensed
- * Now checking family: GillSans BoldCondensed
- * Now checking family: GillSans Italic
- * GillSans Italic includes size 12 and ID 30671.
- * Now checking family: GillSans BoldItalic
- * GillSans BoldItalic includes size 12 and ID 30671.
- *
- * Files:
- *
- * FindFamilies.c
- * FindFamilies.make
- *
- * Version 1.0 MD
- *
- * Done in 1992, but first released in 1994.
- *
- *
- ******************************************************************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <strings.h>
- #include <fonts.h>
- #include <resources.h>
- #include <OSUtils.h>
- #include <GestaltEqu.h>
- #include <Folders.h>
- #include <memory.h>
-
- /******************************************************************************
- *
- * Some things for the Fonts folder in 7.1 that aren't in the header files
- * on the GM disk. These things are defined in ETO #13 headers, so if you have
- * those or later, you don't need to uncomment the GetNextFOND declaration.
- *
- ******************************************************************************/
-
- #define kFontFolderType 'font'
- // pascal Handle GetNextFOND(Handle fondHandle) = {0x700A, 0xA822};
-
- /* These are #defined here because if they're not, some of the expressions below
- get really ugly... */
-
- #define destEntry (*((AsscEntry **)destAsscTableHandle))
- #define srcEntry (*((AsscEntry **)srcAsscTableHandle))
-
-
-
- /******************************************************************************
- *
- * Typedefs, etc.
- *
- ******************************************************************************/
-
-
- /******************************************************************************
- *
- * Prototypes
- *
- ******************************************************************************/
-
-
-
- Handle FindFamilyFOND (char *familyName);
- Boolean IsFontsFolder (void);
- short BuildAsscTableHandle (Handle fondHandle, Handle *theNewHandle);
- void CheckTables(short numSrcEntries, short numDestEntries, Handle srcAsscTableHandle,
- Handle destAsscTableHandle, Str255 theName);
-
-
-
- /******************************************************************************
- *
- * IsFontsFolder returns TRUE if the Fonts folder (and therefore, GetNextFOND
- * is present, and FALSE if it's not.
- *
- ******************************************************************************/
-
- Boolean IsFontsFolder (void)
- {
-
- Boolean foundIt;
- OSErr myError;
- long feature;
-
- short foundRefNum;
- long foundDirID;
-
- #define Gestalttest 0xA1AD
- #define NoTrap 0xA89F
-
- foundIt = false; /* just in case */
-
- if ((NGetTrapAddress(Gestalttest,OSTrap) != NGetTrapAddress(NoTrap,ToolTrap))) {
- myError = Gestalt(gestaltFindFolderAttr, &feature);
- if (!myError) {
- if (feature & gestaltFindFolderPresent) {
- myError = FindFolder(kOnSystemDisk,kFontFolderType,kDontCreateFolder,
- &foundRefNum, &foundDirID);
-
- if (!myError)
- foundIt = true; /* All we care about is finding it */
- }
- }
- }
-
- return foundIt;
-
- }
-
-
- /************************************************************************
- *
- * FindFamilyFOND takes the given font family name and finds the FOND (or, in
- * System 7.1, the first FOND) for that family name.
- *
- *************************************************************************/
-
- Handle FindFamilyFOND (char *familyName)
- {
- Str255 nameString;
- Handle theHandle;
- OSErr myError;
-
- strcpy(nameString, familyName ); /* copy to not mess with original */
- theHandle = GetNamedResource('FOND',c2pstr(nameString));
- if ((((myError = ResError()) != noErr)) || (theHandle == NULL)) {
- printf("Error getting %s FOND resource -- %d\n",familyName,myError);
- }
- return theHandle;
-
- }
-
- /******************************************************************************
- *
- * CheckTables takes two handles to font association tables and a count of the
- * number of entries in each and prints a warning if any of them match. It
- * also takes a Str255 with the name of the destination FOND for printing.
- *
- ******************************************************************************/
-
- void CheckTables(short numSrcEntries, short numDestEntries, Handle srcAsscTableHandle,
- Handle destAsscTableHandle, Str255 theName)
- {
-
- short countSrc, countDest;
- int ignore;
-
- for (countSrc = 0; countSrc <= numSrcEntries; countSrc++) {
- for (countDest = 0; countDest <= numDestEntries; countDest++) {
- if ((srcEntry[countSrc].fontSize == destEntry[countDest].fontSize) &&
- (srcEntry[countSrc].fontID == destEntry[countDest].fontID))
- ignore = printf(" %s includes size %d and ID %d.\n",theName,
- srcEntry[countSrc].fontSize, srcEntry[countSrc].fontID);
- }
- }
- }
-
- /******************************************************************************
- *
- * PrintTable prints all the entries in a table, enclosed in a handle.
- *
- ******************************************************************************/
-
- void PrintTable(short count, Handle srcAsscTableHandle, Str255 theName)
- {
-
- short tempCount;
-
- printf("Source FOND %s contains %d entries:\n\n",theName,count+1);
-
- for (tempCount = 0; tempCount <= count; tempCount++) {
- printf(" Entry %d: Size %3d, ID %5d\n",tempCount,srcEntry[tempCount].fontSize,srcEntry[tempCount].fontID);
- }
- }
-
-
-
- /******************************************************************************
- *
- * BuildAsscTableHandle returns a new handle that contains a copy of a FOND's
- * association table. The FOND handle is passed as input, as is a pointer to
- * the place to return the handle. The result is a short indicating how many
- * entries are in the table.
- *
- ******************************************************************************/
-
- short BuildAsscTableHandle (Handle fondHandle, Handle *theNewHandle)
- {
-
- OSErr myErr;
- short theCount;
- Ptr tempPtr;
-
- tempPtr = *fondHandle;
- tempPtr += sizeof(FamRec);
- theCount = (* ((short *)tempPtr));
-
- tempPtr += sizeof(short); /* move past the count */
-
- myErr = PtrToHand(tempPtr, theNewHandle, (sizeof(AsscEntry) * (theCount+1)));
- if (myErr) {
- printf("### Nasty memory error -- %d",MemError());
- exit(1);
- }
-
- return theCount;
- }
-
- int main(int argc, char * argv[])
- {
- Boolean gHasFontsFolder = false;
- short numFONDs, numSrcEntries, numDestEntries;
- short tempID, ignore;
- OSType tempType;
- Str255 tempName;
- short countFONDs;
- Handle srcFONDHandle, srcAsscTableHandle, destFONDHandle, destAsscTableHandle;
-
- if (argc != 2 ) {
- printf("### Usage: FindFamilies fontfamilyname\n");
- exit(1);
- }
- gHasFontsFolder = IsFontsFolder();
-
- numFONDs = CountResources('FOND');
- srcFONDHandle = FindFamilyFOND(argv[1]);
- if (srcFONDHandle != NULL) {
- numSrcEntries = BuildAsscTableHandle(srcFONDHandle, &srcAsscTableHandle);
- GetResInfo(srcFONDHandle, &tempID, &tempType, &tempName);
- p2cstr(tempName);
- PrintTable(numSrcEntries, srcAsscTableHandle, tempName);
-
- for (countFONDs = 1;countFONDs <= numFONDs;countFONDs++) {
- destFONDHandle = GetIndResource('FOND',countFONDs);
-
- if (destFONDHandle != NULL) {
- GetResInfo(destFONDHandle, &tempID, &tempType, &tempName);
- p2cstr(tempName);
- ignore = printf("Now checking family: %s\n",tempName);
-
- numDestEntries = BuildAsscTableHandle(destFONDHandle, &destAsscTableHandle);
- /* PrintTable(numDestEntries, destAsscTableHandle, tempName); */
-
- CheckTables(numSrcEntries, numDestEntries, srcAsscTableHandle, destAsscTableHandle,
- tempName) ;
- DisposeHandle(destAsscTableHandle);
-
- if (gHasFontsFolder) {
- destFONDHandle = GetNextFOND(destFONDHandle);
- while (destFONDHandle != NULL) {
- numDestEntries = BuildAsscTableHandle(destFONDHandle, &destAsscTableHandle);
- CheckTables(numSrcEntries, numDestEntries, srcAsscTableHandle, destAsscTableHandle,
- tempName);
- DisposeHandle(destAsscTableHandle);
- }
- }
-
- ReleaseResource(destFONDHandle);
- } else {
- printf("Error getting FOND resource #%d\n",countFONDs);
- }
-
- }
- } else
- printf("Source FOND could not be loaded.\n");
-
- ReleaseResource(srcFONDHandle);
- ignore = printf("Checking complete.\n");
- return 0;
-
-
- }
-
-